package com.fs.common.sms.vo.response;

import com.fs.common.sms.enums.PassagewayEnum;
import com.fs.common.sms.vo.SendResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @desc 阿里云发送回执对象
 * @author
 */
@Slf4j
public class AliyunResponse extends SendResponse {
    public static final String SEND_SUCCESS = "0";

    public AliyunResponse(String response) {
        this.response = response;
        init();
    }

    private void init(){
        String[] lineN = null;
        log.info("AliyunResponse:" + this.response);
        try {
            this.way = PassagewayEnum.ALIBABA;
            if(StringUtils.isNotBlank(response)){
                String[] result = response.split("\\,");
                if(result.length>0){
                    this.code = result[0];
                    if(this.getCode().equals(SEND_SUCCESS)){
                        this.msg = "发送成功";
                    }else{
                        this.msg = "发送失败";
                        this.code = result[1];
                    }
                }
                if(result.length>1){
                    this.msgId = result[1];
                }
                this.success = SEND_SUCCESS.equals(this.getCode());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
